package com.ytxg.news.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ytxg.news.dto.NewsInfoRespDto;
import com.ytxg.core.dto.RestResp;
import com.ytxg.news.mapper.NewsInfoMapper;
import com.ytxg.news.po.NewsInfo;
import com.ytxg.news.service.INewsService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class NewsServiceImpl implements INewsService {

    @Resource
    private NewsInfoMapper newsInfoMapper;
    @Override
    public RestResp<List<NewsInfoRespDto>> getLatestList() {
        List<NewsInfo> newsInfos = newsInfoMapper.selectList(new QueryWrapper<>());
        List<NewsInfoRespDto> backList = new ArrayList<>();

        for (NewsInfo newsInfo : newsInfos) {
            NewsInfoRespDto build = NewsInfoRespDto.builder().build();
            BeanUtils.copyProperties(newsInfo, build);
            backList.add(build);
        }


        return RestResp.ok(backList);

    }
}
